package com.badibadi.mail;

import java.util.HashMap;
import java.util.Map;

import com.badibadi.mytools.CommonUtils;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.Dialog;
import com.badibadi.mytools.Utils;
import com.badibadi.mytools.Dialog.DialogClistener;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.R.layout;
import com.badibadi.uniclubber.R.menu;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 13 答方：答方选择了再次回复 问方：再次写了满意度调查
 * 
 * @author Administrator
 */
public class Mail42_41Activity extends Mail245Activity {

	AlertDialog al_sheding;
	private Handler mhandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				Utils.ExitPrgress(Mail42_41Activity.this);
				try {
					Utils.showMessage(Mail42_41Activity.this, getResources()
							.getString(R.string.l_net_error));
				} catch (Exception e) {
					// TODO: handle exception
					// throw new NullPointerException("getActivity() is Null");
				}

				break;
			case 2://满意
				Utils.ExitPrgress(Mail42_41Activity.this);

				try {
					Utils.showMessage(Mail42_41Activity.this, getResources()
							.getString(R.string.wx_caozuo_success));
					Intent intent = new Intent(Mail42_41Activity.this,
							Mail43_45Activity.class);
					intent.putExtra("payUserContactShow1Model",
							payUserContactShow1Model);
					startActivity(intent);
					finish();
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 3:
				Utils.ExitPrgress(Mail42_41Activity.this);
				try {
					Utils.showMessage(Mail42_41Activity.this, getResources()
							.getString(R.string.l_xb12));
				} catch (Exception e) {
					// TODO: handle exception
					// throw new NullPointerException("getActivity() is Null");
				}
				break;
			case 4:
				Utils.ExitPrgress(Mail42_41Activity.this);
				try {
					Utils.showMessage(Mail42_41Activity.this, getResources()
							.getString(R.string.wx_caozuo_false));
				} catch (Exception e) {
					// TODO: handle exception
				}

			default:
				break;
			}
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// setContentView(R.layout.activity_mail42_41);
	}

	@Override
	protected void DongTaiPeiZhi() {
		// TODO Auto-generated method stub
		// this.findViewById(R.id.shedingzhixunfei).setVisibility(View.VISIBLE);

		TextView title_mail = (TextView) this.findViewById(R.id.title_mail);
		title_mail.setText(""
				+ getResources().getString(R.string.wx_reply_zhanneixin));
		if (rank.equals("answerer")) {
			this.findViewById(R.id.delete).setVisibility(View.GONE);
			Button shedingzhixunfei = (Button) this
					.findViewById(R.id.shedingzhixunfei);
			shedingzhixunfei.setText(getResources().getString(
					R.string.wx_txt_86));
			shedingzhixunfei.setVisibility(View.VISIBLE);
			shedingzhixunfei.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Toast t = Toast.makeText(Mail42_41Activity.this,
							getResources().getString(R.string.wx_yi_reply),
							Toast.LENGTH_SHORT);
					t.setGravity(Gravity.CENTER, 0, 0);
					t.show();
				}
			});
			TextView tishi = (TextView) this.findViewById(R.id.tishi);
			tishi.setText(getResources().getString(R.string.bumanyi_));
			tishi.setVisibility(View.VISIBLE);
		} else {
			this.findViewById(R.id.delete).setVisibility(View.VISIBLE);
			Button shedingzhixunfei = (Button) this
					.findViewById(R.id.shedingzhixunfei);
			shedingzhixunfei.setText(getResources().getString(
					R.string.wx_manyidu_diaocha));
			shedingzhixunfei.setVisibility(View.VISIBLE);
			shedingzhixunfei.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					LayoutInflater inflater = LayoutInflater
							.from(Mail42_41Activity.this);
					View view = inflater.inflate(R.layout.manyi_or_bumanyi_42,
							null);
					// 退款工作日
					TextView refund_time = (TextView) view
							.findViewById(R.id.refund_time);
					refund_time.setText(""
							+ payUserContactShow1Model.getRefund_time());
					// 满意
					Button queding = (Button) view.findViewById(R.id.queding);
					queding.setOnClickListener(new View.OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub

							Dialog d = new Dialog();
							d.CreateDialog(
									Mail42_41Activity.this,
									getResources().getString(
											R.string.wx_queding),
									getResources()
											.getString(R.string.wx_txt_83));
							d.setOnDialogClistener(new DialogClistener() {

								@Override
								public void ret() {
									// TODO Auto-generated method stub
									al_sheding.dismiss();
								}

								@Override
								public void ok() {
									// TODO Auto-generated method stub
									pay();
									al_sheding.dismiss();
								}
							});

						}
					});
					// 不满意
					Button quxiao = (Button) view.findViewById(R.id.quxiao);
					quxiao.setOnClickListener(new View.OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							displeased();
							al_sheding.dismiss();
						}
					});

					al_sheding = new AlertDialog.Builder(Mail42_41Activity.this)
							.setView(view).show();
				}
			});
			TextView tishi = (TextView) this.findViewById(R.id.tishi);
			tishi.setText(getResources().getString(R.string.wx_yi_reply_kuohao));
			tishi.setVisibility(View.VISIBLE);
		}
	}

	/**
	 * 有咨询费情况---问方满意答方的回答进行付款操作（需谨慎处理）---POST
	 * 
	 * @param $zhaneniId
	 *            站内信ID
	 * 
	 * @param $uid
	 *            登录用户（问方）
	 * 
	 * @param $reply_id
	 *            回复的是哪一条用户消息ID
	 */
	public void pay() {
		{
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("zhaneniId", payUserContactShow1Model.getZhannei_Id());
			map.put("uid", Utils.getUid(Mail42_41Activity.this));
			map.put("reply_id", payUserContactShow1Model
					.getZhannei_usercontact().get(0).getThisMsgId());
			CommonUtils.CommomPostfunction(Mail42_41Activity.this,
					Constants.BadiUrl_1 + "/" + "inform/pay", map, mhandler, 1,
					3, 2, 4);
		}
	}

	// 不满意操作
	public void displeased() {
		Intent intent = new Intent(Mail42_41Activity.this,
				MailbumanyiActivity.class);
		intent.putExtra("payUserContactShow1Model", payUserContactShow1Model);
//		   
		startActivity(intent);
		finish();
	}
}
